/*
 *  Copyright (C) 2010 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_Properties.java
 *
 * Created on 30/12/2010, 16:33:39
 */

package kuasar.plugin.vmcreator.gui.tooltasks.AddHost;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.DefaultListModel;
import javax.swing.tree.TreeModel;
import kuasar.plugin.vmcreator.gui.pn_Main;
import kuasar.plugin.vmcreator.gui.tooltasks.AddHost.Namespace.keyMaps;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_Properties extends javax.swing.JPanel {
    private pn_Summary summary= null;
    private pn_Main main = null;
    private HashMap<String, Object> map = null;
    /** Creates new form pn_Properties */
    public pn_Properties(pn_Summary summary, HashMap<String, Object> map) {
        this.summary=summary;
        this.map=map;
        initComponents();
        preLoad();
        
    }
    public pn_Properties(pn_Main main, HashMap<String, Object> map) {
        this.main= main;
        this.map=map;
        initComponents();
        preLoad();

    }
    private void preLoad(){
        spn_Devices.getViewport().setOpaque(false);
        spn_netdev.getViewport().setOpaque(false);
        tre_Devices.setBackground(new Color(0, 0, 0, 0));
        lst_netdev.setCellRenderer(new Lst_Network_CellRender());
        Load();
    }
    private void Load(){
        Object data = map.get(keyMaps.HYPERVISOR + ".name");
        if (data != null) {
            lbl_Hypervisor.setText((String) data);
        }
        data = map.get(keyMaps.OS);
        if (data != null) {
            lbl_OS.setText((String) data);
        }
        data = map.get(keyMaps.OS_VERSION) + " (" +map.get(keyMaps.OS_VERSION+".arc") + " bits)";
        if (data != null) {
            lbl_Version.setText((String) data);
        }
        data = map.get(keyMaps.MEMORY);
        if (data != null) {
            lbl_Memory.setText(data.toString() + " MB");
        }
        data = map.get(keyMaps.DEVICES);
        if (data != null) {
            tre_Devices.setModel((TreeModel) data);
        }
        tre_Devices.setCellRenderer(new TreeCellModRenderer());
        tre_Devices.setEditable(false);
        data = map.get(keyMaps.NETWORK);
        if (data != null) {
            loadNetDevices((ArrayList<Object[]>) data);
        }
        this.updateUI();
    }

    private void loadNetDevices(ArrayList<Object[]> data) {
        DefaultListModel model = new DefaultListModel();
        for (int i = 0; i < data.size(); i++) {
            Object element[] = new Object[3];
            element[0] = data.get(i)[0];
            element[1] = data.get(i)[1];
            element[2] = "";
            model.addElement(element);
        }

        lst_netdev.setModel(model);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_Hypervisor = new javax.swing.JLabel();
        lbl_General1 = new javax.swing.JLabel();
        lbl_OSf = new javax.swing.JLabel();
        lbl_Versionf = new javax.swing.JLabel();
        lbl_General2 = new javax.swing.JLabel();
        lbl_Memoryf = new javax.swing.JLabel();
        lbl_OS = new javax.swing.JLabel();
        lbl_Version = new javax.swing.JLabel();
        lbl_General3 = new javax.swing.JLabel();
        lbl_Memory = new javax.swing.JLabel();
        spn_Devices = new javax.swing.JScrollPane();
        tre_Devices = new javax.swing.JTree();
        spn_netdev = new javax.swing.JScrollPane();
        lst_netdev = new javax.swing.JList();

        setOpaque(false);

        lbl_Hypervisor.setFont(new java.awt.Font("Droid Sans", 1, 14)); // NOI18N
        lbl_Hypervisor.setForeground(new java.awt.Color(0, 51, 102));
        lbl_Hypervisor.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbl_Hypervisor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/hvsx16.png"))); // NOI18N
        lbl_Hypervisor.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_Hypervisor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_HypervisorMouseReleased(evt);
            }
        });

        lbl_General1.setFont(new java.awt.Font("Droid Sans", 1, 14));
        lbl_General1.setForeground(new java.awt.Color(8, 20, 42));
        lbl_General1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbl_General1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/general.png"))); // NOI18N
        lbl_General1.setText("General");
        lbl_General1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_General1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_General1MouseReleased(evt);
            }
        });

        lbl_OSf.setFont(new java.awt.Font("Droid Sans Mono", 1, 14));
        lbl_OSf.setForeground(new java.awt.Color(116, 139, 175));
        lbl_OSf.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbl_OSf.setText("OS:");

        lbl_Versionf.setFont(new java.awt.Font("Droid Sans Mono", 1, 14));
        lbl_Versionf.setForeground(new java.awt.Color(116, 139, 175));
        lbl_Versionf.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbl_Versionf.setText("Version:");

        lbl_General2.setFont(new java.awt.Font("Droid Sans", 1, 14));
        lbl_General2.setForeground(new java.awt.Color(8, 20, 42));
        lbl_General2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbl_General2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/sys.png"))); // NOI18N
        lbl_General2.setText("System & Storage");
        lbl_General2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_General2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_General2MouseReleased(evt);
            }
        });

        lbl_Memoryf.setFont(new java.awt.Font("Droid Sans Mono", 1, 14));
        lbl_Memoryf.setForeground(new java.awt.Color(116, 139, 175));
        lbl_Memoryf.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbl_Memoryf.setText("Memory:");

        lbl_OS.setForeground(new java.awt.Color(204, 204, 204));
        lbl_OS.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbl_OS.setText(" ");

        lbl_Version.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Version.setText(" ");

        lbl_General3.setFont(new java.awt.Font("Droid Sans", 1, 14));
        lbl_General3.setForeground(new java.awt.Color(8, 20, 42));
        lbl_General3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbl_General3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/netdev.png"))); // NOI18N
        lbl_General3.setText("Network Devices");
        lbl_General3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_General3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_General3MouseReleased(evt);
            }
        });

        lbl_Memory.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Memory.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbl_Memory.setText(" ");

        spn_Devices.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        spn_Devices.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        spn_Devices.setOpaque(false);

        tre_Devices.setForeground(new java.awt.Color(204, 204, 204));
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        tre_Devices.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        tre_Devices.setAutoscrolls(true);
        tre_Devices.setOpaque(false);
        tre_Devices.setRequestFocusEnabled(false);
        tre_Devices.setRootVisible(false);
        spn_Devices.setViewportView(tre_Devices);

        spn_netdev.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        spn_netdev.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        spn_netdev.setOpaque(false);

        lst_netdev.setForeground(new java.awt.Color(204, 204, 204));
        lst_netdev.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lst_netdev.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
        lst_netdev.setOpaque(false);
        lst_netdev.setVisibleRowCount(3);
        spn_netdev.setViewportView(lst_netdev);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(lbl_General1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(36, 36, 36)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lbl_OSf, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lbl_OS, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lbl_Versionf)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lbl_Version, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))))
                            .addComponent(lbl_Hypervisor, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(spn_netdev, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                            .addComponent(lbl_General3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spn_Devices, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_General2)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lbl_Memoryf, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbl_Memory, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(lbl_Hypervisor)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_General1)
                    .addComponent(lbl_General2))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_OSf)
                    .addComponent(lbl_OS)
                    .addComponent(lbl_Memoryf)
                    .addComponent(lbl_Memory, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spn_Devices, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_Versionf)
                            .addComponent(lbl_Version))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbl_General3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spn_netdev, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lbl_HypervisorMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_HypervisorMouseReleased
        loadPanel(0);
}//GEN-LAST:event_lbl_HypervisorMouseReleased

    private void lbl_General1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_General1MouseReleased
        loadPanel(1);
}//GEN-LAST:event_lbl_General1MouseReleased

    private void lbl_General2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_General2MouseReleased
        loadPanel(2);
}//GEN-LAST:event_lbl_General2MouseReleased

    private void lbl_General3MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_General3MouseReleased
        loadPanel(3);
}//GEN-LAST:event_lbl_General3MouseReleased

    private void loadPanel(int id){
        if(summary!=null)
            summary.toolbar.loadPanel(id);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lbl_General1;
    private javax.swing.JLabel lbl_General2;
    private javax.swing.JLabel lbl_General3;
    private javax.swing.JLabel lbl_Hypervisor;
    private javax.swing.JLabel lbl_Memory;
    private javax.swing.JLabel lbl_Memoryf;
    private javax.swing.JLabel lbl_OS;
    private javax.swing.JLabel lbl_OSf;
    private javax.swing.JLabel lbl_Version;
    private javax.swing.JLabel lbl_Versionf;
    private javax.swing.JList lst_netdev;
    private javax.swing.JScrollPane spn_Devices;
    private javax.swing.JScrollPane spn_netdev;
    private javax.swing.JTree tre_Devices;
    // End of variables declaration//GEN-END:variables

}
